package com.wxm.killing.mq.controller;

import com.wxm.killing.mq.bme.BmeParam;
import com.wxm.killing.mq.bme.BmeService;
import com.wxm.killing.mq.bme.Constant;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.Servlet;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description TODO
 * @author: wxm
 * @date: 2019/10/21 20:57
 * @version: 1.0
 */
@Api(tags = "一个controller", value = "一个controller")
@RestController
@RequestMapping(value = "/only")
public class OnlyController {

    @Autowired
    private BmeService bmeService;

    @Transactional
    @GetMapping("/add")
    public void add() {
        Map<String, Object> map = new HashMap<>();
        map.put("name", "zhangsan");
        map.put("age", "11");
        bmeService.add("test", map);
        Map<String, Object> map2 = new HashMap<>();
        map2.put("name", "zhangsan2");
        map2.put("age", "12");
        bmeService.add("test", map2);
    }

    @GetMapping("/list")
    public Object list() {
        BmeParam bmeParam = new BmeParam();
        bmeParam.putLike("name","zhang").putEquals("age",11);
        return bmeService.list("test", bmeParam.getMapParam());
    }

    @PostMapping("/pageList")
    public Object pageList() {
        BmeParam bmeParam = new BmeParam();
        bmeParam.putLike("user_name","zhang");
        bmeParam.put(Constant.CURRENT_PAGE, 2);
        bmeParam.put(Constant.PAGE_SIZE, 1);
        return bmeService.pageList("tb_user", bmeParam.getMapParam());
    }

    @GetMapping("/update")
    public Object update() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", "fdsfs");
        map.put("name", "zhangsan更新");
        return bmeService.update("test", map);
    }

    @GetMapping("/delete")
    public Object delete() {
        return bmeService.delete("test", "fdsfs");
    }

    @GetMapping("/get")
    public Object get() {
        return bmeService.get("test", "fdsfs");
    }


}
